package com.ruoyi.project.tickets.controller;

import java.util.List;

import com.ruoyi.project.tickets.domain.dto.OutStockDto;
import com.ruoyi.project.tickets.domain.dto.SaleDto;
import com.ruoyi.project.tickets.domain.vo.SaleVo;
import com.ruoyi.project.tickets.service.IShopUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.tickets.domain.Sale;
import com.ruoyi.project.tickets.service.ISaleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 销售概况Controller
 * 
 * @author 孙山伟
 * @date 2023-07-01
 */
@RestController
@RequestMapping("/tickets/sale")
public class SaleController extends BaseController
{
    @Autowired
    private ISaleService saleService;
    @Autowired
    private IShopUserService shopUserService;
    /**
     * 查询销售概况列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sale sale)
    {
        sale.setShopId(shopUserService.getShopIdBySystemUser());
        startPage();
        List<SaleVo> list = saleService.selectSaleList(sale);
        return getDataTable(list);
    }

    /**
     * 导出销售概况列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:sale:export')")
    @Log(title = "销售概况", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Sale sale)
    {
        List<SaleVo> list = saleService.selectSaleList(sale);
        ExcelUtil<SaleVo> util = new ExcelUtil<SaleVo>(SaleVo.class);
        return util.exportExcel(list, "sale");
    }

    /**
     * 获取销售概况详细信息
     */
    @PreAuthorize("@ss.hasPermi('tickets:sale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(saleService.selectSaleById(id));
    }

    /**
     * 新增销售概况
     */
    @PreAuthorize("@ss.hasPermi('tickets:sale:add')")
    @Log(title = "销售概况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SaleDto sale )
    {

        return toAjax(saleService.insertSale(sale));
    }

    /**
     * 修改销售概况
     */
    @PreAuthorize("@ss.hasPermi('tickets:sale:edit')")
    @Log(title = "销售概况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sale sale)
    {
        return toAjax(saleService.updateSale(sale));
    }

    /**
     * 删除销售概况
     */
    @PreAuthorize("@ss.hasPermi('tickets:sale:remove')")
    @Log(title = "销售概况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(saleService.deleteSaleByIds(ids));
    }
}
